package b1w1nn1ng.crossf1t.tests;
import b1w1nn1ng.crossf1t.business.*;
import b1w1nn1ng.crossf1t.db.*;
import java.sql.SQLException;

import junit.framework.TestCase;

import org.junit.*;
import static org.junit.Assert.*;



public class TestLogin extends TestCase{

	private String username;
	private String firstName;
	private String lastName;
	private String password;
	private String email;
	private String question;
	private String answer;
	private int friendCode;
	private int id;
	User user2;
	
	protected void setUp(){
		
		username = "user7";
		password = "pass1";
		email = "email1@email.com";
		firstName = "firstname";
		lastName = "lastname";
		question = "What is the answer?";
		answer = "answer";
		friendCode = 1234;
		int height = 1;
		int weight = 2;
		
		user2 = new User(username, password, email, firstName, 
				lastName, question, answer, height, weight);
	}
	public void testCreateUser() throws SQLException, ClassNotFoundException{
		
		
		user2.setId(Login.createAccount(user2).getId());
		//do a test here to verify that the user is in the system
		try {
			assertTrue(user2.equals(Database.getUserByID(user2.getId())));
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public void testGetPasswordRecoveryInformation() throws SQLException, ClassNotFoundException{
		user2.setId(Database.getUserByUsername(user2.getUsername()).getId());
		try {
			//tests if the user object returned by quering the username returns the correct information
			User testUser = Login.getPasswordRecoveryInformation(username);
			assertTrue(testUser.equals(user2));			
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		

		
	}
}
